import os

from google.appengine.ext import webapp

from tasks.models import get_context

def get_id(req, name):
    id = req.get(name, None)
    if id is None:
        return None
    else:
        return int(id)

def handler(post=None, get=None):
    class PostHandler(webapp.RequestHandler):
        def post(self):
            context = get_context(self)
            if context:
                return post(self, context)
        def get(self):
            context = get_context(self)
            if context:
                return get(self, context)
    return PostHandler

def template_path(tpl_name):
    return os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
        'templates',
        tpl_name,
    )

